import zmq

def subscriber():
    context = zmq.Context()
    socket = context.socket(zmq.SUB)
    socket.connect("tcp://localhost:5556")
    socket.setsockopt_string(zmq.SUBSCRIBE, "")

    try:
        while True:
            message = socket.recv_string()
            print(f"Received: {message}")
    except KeyboardInterrupt:
        print("Subscriber stopped.")
    finally:
        socket.close()
        context.term()

if __name__ == "__main__":
    subscriber()
    